from django.contrib.contenttypes.models import ContentType
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Permission

from apps.meiduo_mall_admin.serializers.permission import PermissionSerialzier, ContentTypeSerialzier
from apps.meiduo_mall_admin.utils import PageNum


class PermissionView(ModelViewSet):
    """获取权限数据"""

    # 设置序列化器
    serializer_class = PermissionSerialzier
    queryset = Permission.objects.all()
    pagination_class = PageNum


class ContentTypeAPIView(APIView):
    """获取权限类型列表数据"""
    def get(self,request):
        # 查询全选分类
        content = ContentType.objects.all()
        # 返回结果
        serializer = ContentTypeSerialzier(content,many=True)
        return Response(serializer.data)